/************************************************************************/
/*Copyright (c) James Zhao 2007,2008
/*This file is part of AdminOverlay.
/*AdminOverlay is free software: you can redistribute it and/or modify
/*it under the terms of the GNU General Public License as published by
/*the Free Software Foundation, either version 3 of the License, or
/*(at your option) any later version.
/*
/*AdminOverlay is distributed in the hope that it will be useful,
/*but WITHOUT ANY WARRANTY; without even the implied warranty of
/*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
/*GNU General Public License for more details.
/*
/*You should have received a copy of the GNU General Public License
/*along with AdminOverlay.  If not, see <http://www.gnu.org/licenses/>.                                                                     */
/*************************************************************************/
#pragma  once
#include "GameOverlay.h"
//#include "UIKit.h"
#include "ServerKit.h"
#include "GraphicsAdapter.h"
#include "OverlayConfig.h"
#include "cegui.h"
//#include "ExtensionKit.h"

GameOverlay gameOverlay;
//load the input first b/c once in thread, it doesnt work
void loadImmediate(HINSTANCE instance, DWORD threadID)
{
	gameOverlay.InitalizeImmediateServices(instance, threadID);
}
void render(LPDIRECT3DDEVICE9 dev)
{

}
//loading after dllmain finishes
//prevent loader locks
DWORD WINAPI loadDelayed(LPVOID p)
{
	try
	{
// 		ServerSession *xss = ServerSession::createServerSession(SessionType_XMLRPC, OverlayConfig::currentInstance()->ip,
// 			OverlayConfig::currentInstance()->port,
// 			OverlayConfig::currentInstance()->password);
// 		xss->Connect();
// 		*result = xss->ExecuteCommand("sv_port");
	}
	catch(...)
	{
	}

	gameOverlay.InitalizeDelayedServices();
	gameOverlay.IsActive(true);

	return 0;
}
_declspec(dllexport) BOOL WINAPI DllMain(HINSTANCE hinst, DWORD dwReason, LPVOID reserved)
{ 	
	if(dwReason == DLL_PROCESS_ATTACH)
	{	
		//Sleep(7000);
		loadImmediate(hinst, GetCurrentThreadId());
 		CreateThread(0, 0, loadDelayed, NULL, 0,0);
	}
	else if(dwReason == DLL_PROCESS_DETACH)
	{

	}
	return TRUE;
}
